﻿using LD.BC;
using LD.Host;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LD.Tool
{
    public partial class ToolMoveFrm : FrmToolBase
    {
        public ToolMoveFrm()
        {
            InitializeComponent();
            this.Shown += ToolMoveFrm_Shown;
            this.btn_ok.Click += Btn_ok_Click;
        }

        private void Btn_ok_Click(object sender, EventArgs e)
        {
            if (this.cob_point.SelectedIndex >= 0)
            {
                string pointName = this.cob_point.Text;
                this.TB_Tool.Param = Newtonsoft.Json.JsonConvert.SerializeObject(new Move()
                {
                    WaitOver = this.sw_waitOver.Checked,
                    Point = pointName
                });
            }
        }

        private void ToolMoveFrm_Shown(object sender, EventArgs e)
        {
            Init();
        }
        private void Init()
        {
            if (BcFactory.Instance.Config == null) return;

            foreach (var item in Appbus.PartNo.Config.AxisPoint)
            {
                this.cob_point.Items.Add(item.Name);
            }
            if (this.TB_Tool.Param != null)
            {
                var param = Newtonsoft.Json.JsonConvert.DeserializeObject<Move>(this.TB_Tool.Param);
                if (param != null)
                {
                    this.cob_point.Text = param.Point;
                    this.sw_waitOver.Checked = param.WaitOver;
                };
            }
        }
    }
}
